﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
namespace JumpBall_2
{
    public interface IMessage : IEventSystemHandler
    {
        // 可通过消息系统调用的函数
        void Message1(int num);
    }

    public class ScoreView : MonoBehaviour, IMessage
    {
        public Text text;
        public Text maxText;        //最高分
        private int score = 0;
        public int Score
        {
            get => score;
        }

        private void Start()
        {
            ShowMax();
        }

        void ShowMax()
        {
            int maxScore = PlayerPrefs.GetInt("max-score");
            if (score > maxScore)
            {
                maxScore = score;
            }
            PlayerPrefs.SetInt("max-score", maxScore);
            maxText.text = maxScore.ToString();
        }

        public void AddScore(int num)
        {
            Debug.Log("AddScore:" + num);
            score += num;
            text.text = score.ToString();

            ShowMax();
        }

        public void Message1(int num)
        {
            if (GameManager.Instance.gameState == GameState.Start)
            {
                AddScore(num);
            }

        }
    }
}